package com.vodone.v1pin.user.delegate
{
	
	import com.vodone.v1pin.ServiceProvider;
	import com.vodone.v1pin.core.model.MainModelLocator;
	import com.vodone.v1pin.core.service.HttpJsonDelegate;
	
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import mx.rpc.http.mxml.HTTPService;
	
	[Bindable]
	public class RegisterDelegate
	{
		/**
		 * 注册 
		 * @param resultHandler
		 * @param type
		 * @param userName
		 * @param password
		 * @param confirmPass
		 * @param email
		 * @param jz
		 * @param faultHandler
		 * @param context
		 * 
		 */		  
		public static function register( resultHandler:Function , type:String , userName:String , password:String , confirmPass:String = null , email:String = null , jz:Boolean = false , sinaCount:String = "", faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().registerService;
			var params:Object = {
				type : type,
				userName : userName,
				password : password,
				email : email,
				sinanum : sinaCount,
				sconfirmPassword : confirmPass
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		public static function v1Logout( resultHandler:Function = null , faultHandler:Function = null , context:Array = null ):void
		{
			var params:Object = {
			}
			var service:HTTPService = ServiceProvider.getInstance().logoutV1Service;
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		} 
		
		private static function httpEncoding(param:String):String
		{    //转码 
			return encodeURIComponent(param); 
		} 
		
		private static function openSelfStr(deleteStr:String):String
		{    //解码 
			return decodeURIComponent(deleteStr); 
		} 
		
		public static function threeLogin( resultHandler:Function , name:String , version:String , type:String = "threelogin" , faultHandler:Function = null , context:Array = null ):void
		{
			
			var myUrl:String = ExternalInterface.call("window.location.href.toString");
			
			var rt:String = httpEncoding("#");
			var urlArr:Array = myUrl.split("#");
//			myUrl = urlArr[0];
			myUrl = myUrl.replace("#",rt);
			
			var url:String = "http://u.v1.cn/ids/oauthforward.do";
			url += "?name=" + name + "&version=" + version + "&callbackUrl=" + myUrl;
			//			url += "?ordernum=" + "1054111101730" + "&ordertype=" + "2";
			var request:URLRequest=new URLRequest(url);  
			
			
			
			
			
//			url = "http://u.v1.cn/ids/oauthforward.do?name=msn&version=2.0&callbackUrl=http://v1test.suizui.net"
			navigateToURL(request,"_self");  
			
			
			/*var service:HTTPService = ServiceProvider.getInstance().threeLoginService;
			var params:Object = {
				type : type,
				name : name,
				version : version
			}
				
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );*/
		}
		
		/**
		 * 检查是否登陆 
		 * @param resultHandler
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function checkLogin( resultHandler:Function , faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().checkLoginService;
			var params:Object = {
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		/**
		 * 检查第三方是否登陆 
		 * @param resultHandler
		 * @param faultHandler
		 * @param context
		 * 
		 */		
		public static function checkThreeLogin( resultHandler:Function , faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().checkThreeLoginService;
			var params:Object = {
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		public static function registerActive( resultHandler:Function , faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().registerActiveService;
			var params:Object = {
				params1 : "hello",
				params2 : "hello"
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
		
		public static function getVerifyCode( resultHandler:Function , faultHandler:Function = null , context:Array = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().getVerifyCodeService;
			var params:Object = {
				params1 : "hello",
				params2 : "hello"
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler , context );
		}
	}
}